﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NextCMS.Models;

/// <summary>
/// Summary description for Forms
/// </summary>
/// 
namespace Modules
{
    public class Forms : IPageModule
    {

        public string GetLayoutModeHTML(PageModuleModel pmm, ModuleModel mm, int UserLanguageId)
        {
            if (pmm.SubModuleId > 0)
            {

                string width = "600";
                string height = "230";

                SubModule sm = mm.SubModules.Where(c => c.Id == pmm.SubModuleId).FirstOrDefault();
                string url = VirtualPathUtility.ToAbsolute(sm.Settings);
                url = url + "?Id=" + pmm.RefId + "&PageModuleId=" + pmm.Id + "";
                return "<div class='Module' onclick='javascript:OpenEditModuleDialog(\"" + mm.Code + "\"," + pmm.RefId + "," + pmm.Id + ",\"" + url + "\"," + width + "," + height + ");'>" + mm.Name + ": " + sm.Name + "</div>";
            }
            else
                return "";
        }

        public string GetViewModeHTML(PageModuleModel pmm, ModuleModel mm, int UserLanguageId)
        {
            if (pmm.SubModuleId > 0)
            {
                SubModule sm = mm.SubModules.Where(c => c.Id == pmm.SubModuleId).FirstOrDefault();
                if (sm.Code == "ContactUs")
                {
                    PageFormsHelper pfc = new PageFormsHelper();
                    PageContactUsFormModel contactForm = pfc.GetById<PageContactUsFormModel>(pmm.RefId);
                    if (contactForm != null)
                        return "<%@ Register src=\"Modules/Forms/ContactUsForm.ascx\" tagname=\"ContactUsForm\" tagprefix=\"uc1\" %><uc1:ContactUsForm RedirectToURL=\"" + contactForm.RedirectToURL + "\"  SendEmailTo=\"" + contactForm.SendEmailTo + "\" ID=\"ContactUsForm1\" runat=\"server\" />";
                    else
                        return "";
                }
                else
                    return sm.Name;
            }
            else
                return "";
        }
    }
}